/**
 * Created by Administrator on 2014/12/26.
 */

function Sokobangame(){

    this.statusdiv=dom("DIV",null,"1个雷等待你去扫哟!");

    var btnnewgame=  dom("BUTTON",null,"新游戏");
    //    btnnewgame.addEventListener("click",bind(this.newgame,this));
    btnnewgame.addEventListener("click",this.newgame);
   document.body.addEventListener("click",bind(this.clickhanlder,this));
    this.container=dom("DIV",null,
        dom("H1",null,"扫雷游戏")
        ,dom("DIV",null,
            btnnewgame
        )
        ,this.statusdiv
    );
    this.node=dom("DIV",null);
    this.container.appendChild(this.node);
    document.body.appendChild(this.container);
}

Sokobangame.prototype.clickhanlder=function(e){
    if(e.target.pos){
        var square= e.target.square;
        if(square.data=="*"){
            alert("Mission Failed!!!");
        }else{
            this.field.showaround(square);
            if(this.field.won()){
                alert("You win!!!");
            }
        }
    }

}

Sokobangame.prototype.updatestatus=function(){
    this.statusdiv.innerHTML=this.field.boulders+"个小球等待你去推哟!";
}


Sokobangame.prototype.newgame=function(){
    this.node.parentNode.removeChild(this.node);
    this.node=dom("DIV",null);
    this.container.appendChild(this.node);
    this.field=new Sokobanfield(this.node);
}

